

#import "ListofDepartmentsViewController.h"
#import "DepartmentViewController.h"
#import "Department.h"


@implementation ListofDepartmentsViewController



#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.title = NSLocalizedString(@"Departments",nil);


}


- (void)viewWillAppear {
	[self.tableView reloadData];
	self.tableView.bounces=NO;
	self.tableView.alwaysBounceVertical=NO;
	self.tableView.bouncesZoom=NO;
}


- (void)viewDidUnload {
	// Release any properties that are loaded in viewDidLoad or can be recreated lazily.
}


#pragma mark -
#pragma mark Table view data source methods

/*
 The data source methods are handled primarily by the fetch results controller
 */

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    	
	return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	
	return 0;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
		
		cell.textLabel.font=[UIFont fontWithName:@"Verdana" size:16];
		cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
    }
    
    // Configure the cell.
	[self configureCell:cell atIndexPath:indexPath];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    Department *dept = [fetchedResultsController objectAtIndexPath:indexPath];
//	//NSString *name = dept.Name;
//	
//	static NSString *CellIdentifier = @"Cell";
//    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//    if (cell == nil) {
//        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//    }
	
	//[name sizeWithFont:cell.textLabel.font constrainedToSize:cell.textLabel. lineBreakMode:
	return  50;
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
	
    // Configure the cell to show the book's title
	
//	Department *dept = [fetchedResultsController objectAtIndexPath:indexPath];
//	cell.textLabel.numberOfLines=2;
//	cell.textLabel.text = dept.Name;
//	
//	NSMutableString *icon=[[NSMutableString alloc] initWithString:dept.Abbreviation];
//	[icon appendString:@"_icon.png"];
//	
//	UIImage *image = [UIImage imageNamed:icon];
//	
//	if(image != nil)
//		cell.imageView.image=image;
//	
//	if (([[dept Abbreviation] compare:@"CAN"]==0) || ([[dept Abbreviation] compare:@"BUS"]==0)){
//		cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
//		cell.selectionStyle = UITableViewCellSelectionStyleBlue;
//		cell.textLabel.textColor=[UIColor blackColor];
//
//		
//	}
//	else{
//			cell.accessoryType =  UITableViewCellAccessoryNone;
//			cell.selectionStyle = UITableViewCellSelectionStyleNone;
//			cell.textLabel.textColor=[UIColor lightGrayColor];
//
//	}
//	
//	[icon release];
		
}

//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
//	// Display the authors' names as section headings.
//    return [[[fetchedResultsController sections] objectAtIndex:section] Name];
//}





#pragma mark -
#pragma mark Selection and moving

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
//    // Create and push a detail view controller.
//	DepartmentViewController *departmentViewController = [[DepartmentViewController alloc] initWithStyle:UITableViewStylePlain];
//    Department *selectedDept = (Department *)[[self fetchedResultsController] objectAtIndexPath:indexPath];
//	
//	UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//	if (cell.selectionStyle == UITableViewCellSelectionStyleNone) {
//		[departmentViewController release];
//		return;
//	}
//	
//	// Pass the selected book to the new view controller.
//    departmentViewController.department = selectedDept;
//	departmentViewController.managedObjectContext=[self managedObjectContext];
//	[self.navigationController pushViewController:departmentViewController animated:YES];
//	[departmentViewController release];
}


- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // The table view should not be re-orderable.
    return NO;
}





#pragma mark -
#pragma mark Memory management


- (void)dealloc {
    [super dealloc];
}

@end

